﻿#ifndef CONTROLROBOTMOVEWIDGET_H
#define CONTROLROBOTMOVEWIDGET_H

#include "BaseClass/BaseWidget.h"
#include <QShortcut>
#include "OneRobot/RobotLibraryGloable.h"
#include "RobotStateInfo.h"

class CMaskWidget;
class QPushButton;

namespace Ui {
class ControlRobotMoveWidget;
}
namespace RO_Robot{

class SteerMeter;
class SettingRobotSpeed;
class ControlTimer;
class PeripheralListDlg;
class SteerAngleDlg;

class RobotLibrary_EXPORT ControlRobotMoveWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ControlRobotMoveWidget(QWidget *parent = 0);
    ~ControlRobotMoveWidget();
    void init();
    void initMode(int mode);
    void setValue(qreal value);
    QPushButton *createMoveButton(const QString &toolTip, const QString &objectName, const QString &shortcutStr);
    QStringList getShortcutKeys() const;
    void setShortcutKeys(const QStringList &value);
    int chassisMode() const;

    bool isCompatibilityMode() const;
    void stopAllTimer();
    void setSteerValue(const QString &key,qreal value);
    void setSteerValue(const QVariantMap &map);
    QString getIp() const;
    void setIp(const QString &ip);

    void updateRobotStateInfo(const RO_Network::RobotStateInfo *info);

public slots:

    void slotRobotControlSettingButton();
    void slotControlSpeed(int type, qreal vx, qreal vy, qreal w, qreal steer);
    void slotPeripheralBtnCliecked(bool checked);
    void slotSteerAngleDlgParameter(qreal angle);
    void slotSteerAngle();
    void slotSteerAngleDlgClosed();
    void slotSettingRobotSpeed();
    void slotSendGlobalMsg(int sgs, const QVariant &var);
protected:
    //按下移动按键.
    bool pressedMoveKey(const QString &key);
    //释放移动按键.
    bool releaseMoveKey(const QString &key, const QString &fromClassName);
    void keyPressEvent(QKeyEvent *e) override;
    void keyReleaseEvent(QKeyEvent *e) override;
    void leaveEvent(QEvent *event) override;
    bool event(QEvent *event) override;
signals:
    //打开手柄配置
    void sigOpenJoyStickConfigDlg();
    void sigControlStateChanged(bool isControl);
private:
    Ui::ControlRobotMoveWidget *ui;
    SteerMeter *pSteerMeter {Q_NULLPTR};
    ControlTimer *pControlTimer {Q_NULLPTR};
    SettingRobotSpeed *pSettingRobotSpeed {Q_NULLPTR};

    int _mode = 0; //
    QStringList _shortcutKeys;
    QPushButton *_peripheralBtn {Q_NULLPTR};
    PeripheralListDlg * _periperalListDlg {Q_NULLPTR};
    SteerAngleDlg *_steerAngleDlg {Q_NULLPTR};

    QList<QShortcut*>_shortcutList; //快捷键列表
    qreal _robotMaxRot = 360;//°
    qreal _robotMaxSpeed = 5;//m/s
    //电机 json 数组
    QVariantList _motorList;
    QString _modeStr;
    //<steer_angles%1
    QMap<QString,SteerMeter*>_steerMap;
    //<motor_name
    QMap<QString,SteerMeter*>_motorSteerMap;
    QString _ip;
    CMaskWidget * _cMaskWidget {Q_NULLPTR};
    //当为多舵轮时，保存舵轮列表
    //motorName:
    QVariantList _steerList;
    //手柄
    QString _robokitVersion ;
};
}//namespace
#endif // CONTROLROBOTMOVEWIDGET_H
